<!--
 * @Author: LENOVO\zhangch17 zhangch17@Lenovo.com
 * @Date: 2022-11-14 15:12:43
 * @LastEditors: LENOVO\zhangch17 zhangch17@Lenovo.com
 * @LastEditTime: 2022-11-21 16:47:48
 * @FilePath: \todolist\src\views\one.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <el-button @click="Create">Create</el-button>
    <el-button @click="speed">speed of progress</el-button>
    <!-- <el-progress type="circle" :percentage="25"></el-progress> -->
    <board ref="board"></board>
    <!-- 新增弹窗 -->
    <newDialogVue ref="newDialogVue"></newDialogVue>
    <!-- 进度弹窗 -->
  </div>
</template>

<script>
import fs from 'fs'
import board from './board/board.vue'
import newDialogVue from './newDialog.vue'
export default {
  components: { board, newDialogVue },
  data () {
    return {
      jsonStr: '',
    }
  },
  mounted () {
    //进入页面 自动获取一次
    this.$nextTick(() => {
      this.readFile()
      // const that = this
      // fs.readFile("./joe.json", function (err, data) {
      //   if (err) {
      //     fs.writeFileSync('./joe.json', '{ "todo": [ { "title": "测试数据3标题", "level": "p3", "startDate": "2022-10-20", "deadline": "2023-10-02", "describe": "嗡嗡嗡", "time": "18:50:18", "image": [], "state": "todo" } ], "pending": [ { "title": "测试数据4标题", "level": "p4", "startDate": "2022-10-20", "deadline": "2023-10-02", "describe": "嗡嗡嗡", "time": "18:50:18", "image": [], "state": "pending" } ], "done": [ { "title": "测试数据1标题", "level": "p1", "startDate": "2022-10-20", "deadline": "2023-10-02", "describe": "嗡嗡嗡", "time": "18:50:18", "image": [], "state": "done" } ] }');
      //     fs.readFile("./joe.json", function (err, data) {
      //       if (err) console.log(err)
      //       let a = data.toString()
      //       that.jsonStr = a
      //       that.$refs.board.init(JSON.parse(that.jsonStr))
      //     })
      //   } else {
      //     let a = data.toString()
      //     that.jsonStr = a
      //     that.$refs.board.init(JSON.parse(that.jsonStr))
      //   }
      // })
    })
  },
  methods: {
    readFile () {
      const that = this
      fs.readFile("./joe.json", function (err, data) {
        if (err) {
          fs.writeFileSync('./joe.json', '{ "todo": [ { "title": "测试数据3标题", "level": "p3", "startDate": "2022-10-20", "deadline": "2023-10-02", "describe": "嗡嗡嗡", "time": "18:50:18", "image": [], "state": "todo" } ], "pending": [ { "title": "测试数据4标题", "level": "p4", "startDate": "2022-10-20", "deadline": "2023-10-02", "describe": "嗡嗡嗡", "time": "18:50:18", "image": [], "state": "pending" } ], "done": [ { "title": "测试数据1标题", "level": "p1", "startDate": "2022-10-20", "deadline": "2023-10-02", "describe": "嗡嗡嗡", "time": "18:50:18", "image": [], "state": "done" } ] }');
          fs.readFile("./joe.json", function (err, data) {
            if (err) console.log(err)
            let a = data.toString()
            that.jsonStr = a
            that.$refs.board.init(JSON.parse(that.jsonStr))
          })
        } else {
          let a = data.toString()
          that.jsonStr = a
          that.$refs.board.init(JSON.parse(that.jsonStr))
        }
      })
    },
    Create () {
      this.$refs.newDialogVue.init(this.jsonStr)
    },
    board () {
      this.$refs.board.init()
    },
    speed () {

    }
  }
}
</script>

<style>
</style>